package com.bothin.experiment4.controller;

import com.bothin.experiment4.model.Employee;
import com.bothin.experiment4.security.LoginUserUtil;
import com.bothin.experiment4.service.IEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.Map;

/**
 * Created by bothin
 * At 2019/12/22 15:49
 * Description:
 */
@Controller
@RequestMapping("/user/common")
public class UserCommonController {
    @Autowired
    private IEmployeeService employeeService;

    @RequestMapping("/info")
    public ModelAndView to_user_info(Map<String,Object> map){
        Employee employee = employeeService.findById(LoginUserUtil.getLoginUser().getEmployeeId());
        map.put("employee",employee);
        return new ModelAndView("user/user_info");
    }

    @RequestMapping("/change/info")
    public ModelAndView change_info(Employee employee){
        employeeService.update(employee);
        return new ModelAndView("redirect:/user/common/info");
    }
}
